package use.thread.executor;

import use.thread.One;

import java.util.concurrent.*;

/**
 * 主要有三种 Executor：
 * 1.CachedThreadPool：一个任务创建一个线程；
 * 2.FixedThreadPool：所有任务只能使用固定大小的线程；
 * 3.SingleThreadExecutor：相当于大小为 1 的 FixedThreadPool。
 */
public class ExecutorMain {
    public static void main(String[] args) throws InterruptedException {
        //ExecutorService cachedExecutorService = new ThreadPoolExecutor(10,20,10, TimeUnit.MICROSECONDS,new LinkedBlockingQueue<Runnable>());
        ExecutorService cachedExecutorService = Executors.newCachedThreadPool();
        ExecutorService fixedExecutorService = Executors.newFixedThreadPool(1);
        ExecutorService SingleExecutorService = Executors.newSingleThreadExecutor();
        cachedExecutorService.execute(new One());
        cachedExecutorService.execute(new One());
//        Thread.sleep(5000);
        cachedExecutorService.shutdown();
        fixedExecutorService.execute(new One());
        fixedExecutorService.execute(new One());
        fixedExecutorService.shutdown();
    }
}
